package com.yanq.liancar.adapter;


import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yanq.liancar.R;
import com.yanq.liancar.bean.SmallCFuelFillBean;
import com.yanq.liancar.util.LogUtils;

import java.util.List;

public class SmallCFuelFillAdapter extends BaseAdapter {

    private List<SmallCFuelFillBean> dataList;
    private LayoutInflater mInflater;
    private Context context;


    public SmallCFuelFillAdapter(Context context, List<SmallCFuelFillBean> dataList) {
        this.context = context;
        this.dataList = dataList;
        mInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.fuelfilling_item, null);
            holder.discount_price=convertView.findViewById(R.id.tv_discount_price);
            holder.price=convertView.findViewById(R.id.tv_price);
            holder.ll_price=convertView.findViewById(R.id.ll_price);
            holder.rl_vip=convertView.findViewById(R.id.rl_vip);
            holder.tv_shoujia=convertView.findViewById(R.id.tv_shoujia);
            holder.tv_yuan=convertView.findViewById(R.id.tv_yuan);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        SmallCFuelFillBean bean = dataList.get(position);
        holder.price.setText(bean.getPrice()+"");
        if (bean.isChecked()){
            LogUtils.e("11111",bean.isChecked()+"");
            holder.ll_price.setBackground(context.getResources().getDrawable(R.drawable.selector_tv_bg_b));
            holder.price.setTextColor(Color.WHITE);
            holder.discount_price.setTextColor(Color.WHITE);
            holder.discount_price.setText(bean.getDiscount_price()+"");
            holder.tv_shoujia.setTextColor(Color.WHITE);
            holder.tv_yuan.setTextColor(Color.WHITE);
        }else {
            holder.ll_price.setBackground(context.getResources().getDrawable(R.drawable.selector_tv_bg_a));
            holder.price.setTextColor(context.getResources().getColor(R.color.main_color));
            holder.discount_price.setTextColor(context.getResources().getColor(R.color.main_color));
            holder.discount_price.setText(bean.getDiscount_price()+"");
            holder.tv_shoujia.setTextColor(context.getResources().getColor(R.color.main_color));
            holder.tv_yuan.setTextColor(context.getResources().getColor(R.color.main_color));
        }
//        if (bean.getId()>2){
//            holder.rl_vip.setVisibility(View.VISIBLE);
//
//        }else {
//            holder.rl_vip.setVisibility(View.GONE);
//        }

        if (bean.getId()<3){
            holder.rl_vip.setBackground(context.getResources().getDrawable(R.mipmap.bjhy));
        }else {
            holder.rl_vip.setBackground(context.getResources().getDrawable(R.mipmap.bojhy));
        }

        return convertView;
    }

    private class ViewHolder {
        TextView price;
        TextView discount_price;
        RelativeLayout ll_price;
        RelativeLayout rl_vip;
        TextView tv_shoujia;
        TextView tv_yuan;

    }

    public  void setData( List<SmallCFuelFillBean>  list){
        this.dataList=list;
        notifyDataSetChanged();
    }
}
